using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using FastSpring.Web.Ajax;
using FastSpring.Web.Ajax.WebSupport;

namespace FastSpring.Web.WebControls
{
    public class AjaxScript : WebControl
    {
        [DefaultValue("/Html/Scripts/")]
        public string BasePath
        {
            get
            {
                object o = ViewState["BasePath"];

                if (o == null)
                    o = System.Configuration.ConfigurationSettings.AppSettings["AjaxScript:BasePath"];

                return (o == null ? "/Html/Scripts/" : (string)o);
            }
            set { ViewState["BasePath"] = value; }
        }        
        protected override void Render(HtmlTextWriter writer)
        {
            if (this.Page is IAjaxAware)
            {
                IAjaxAware AjaxAware = this.Page as IAjaxAware;
                string appPath = this.Page.Request.ApplicationPath.TrimEnd('/');
                writer.WriteLine("<script language=\"javascript\" type=\"text/javascript\" src=\"" + appPath + this.BasePath + "prototype-1.6.0.js\" charset=\"utf-8\"></script>");
                writer.WriteLine("<script language=\"javascript\" type=\"text/javascript\" src=\"" + appPath + this.BasePath + "fsajax-2.05.js\" charset=\"utf-8\"></script>");
                writer.WriteLine("<script language=\"javascript\" type=\"text/javascript\" src=\"" + appPath + AjaxHelper.AjaxHead + AjaxAware.AjaxActionHandler.HandlerUrl + "\" charset=\"utf-8\"></script>");
            }
            //base.Render(writer);
        }
    }
}
